/*
 * CS_STOP.cpp
 *
 *  Created on: 2013. 5. 21.
 *      Author: the2
 */

#include "../../User.h"
#include "CS_STOP.h"

#include "../../NLogic/Static.h"
#include "../../NLogic/Battle.h"

namespace ProjectZ { namespace NCommand { namespace NAction {

void CS_STOP::OnExecute(User * pUser, ::Network::Packet * pPacket)
{
	/*
	 * CS_STOP	0x0403	10
	 * 		4	unsigned int	GID
			2	posx	x 좌표
			2	posy	y 좌표
			2	degree	방향벡터정보
			1	char	몬스터여부 (0 : 주인공 1: 몬스터 2: 주인공소환, 3: 몬스터 소환)


			SC_STOP	0x0404	10
			4	unsigned int	GID
			2	posx	x 좌표
			2	posy	y 좌표
			2	degree	방향벡터정보
			1	char	몬스터여부 (0 : 주인공 1: 몬스터 2: 주인공소환, 3: 몬스터 소환)
	 *
	 */

	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
		return;

	PREPARE_PACKET;

	unsigned int GID = 0;
	int16_t x = 0;
	int16_t y = 0;
	int16_t degree = 0;
	int8_t ismonster = 0;

	* pPacket >> GID >> x >> y >> degree >> ismonster;

	int targetgid = 0;
	if( ismonster == 0 )
	{
		targetgid = pUser->GetUserSeq();

//		pUser->player_info.x = x;
//		pUser->player_info.y = y;
//		pUser->player_info.degree = degree;
//		pUser->player_info.speed = 0;

		if (pSpace->GetData()._spaceType == NLogic::Space::SpaceType::BATTLEROYAL && pUser->GetEnumState() == User::EnumState::BATTLE_ROYAL_BATTLE)
		{
			pUser->GetBattleRoyalBattle()->GetData().x = x;
			pUser->GetBattleRoyalBattle()->GetData().y = y;
			pUser->GetBattleRoyalBattle()->GetData().degree = degree;
			pUser->GetBattleRoyalBattle()->GetData().speed = 0;

			DEBUGLOG("GetBattleRoyalBattle CS_STOP x : %d", x);
		}
		else
		{
			pUser->GetBattle()->GetData().x = x;
			pUser->GetBattle()->GetData().y = y;
			pUser->GetBattle()->GetData().degree = degree;
			pUser->GetBattle()->GetData().speed = 0;
		}
	}
	else if( ismonster == 1 )
	{
		targetgid = GID;
		NLogic::Monster * pMonster = pUser->GetSpace()->GetMonster(targetgid);
		if (NULL != pMonster)
		{
			pMonster->GetData().x = x;
			pMonster->GetData().y = y;
			pMonster->GetData().degree = degree;
		}
	}
	else if( ismonster == 2 )
	{
		targetgid = GID;
		NLogic::Monster * pMonster = pUser->GetSpace()->GetMonster(targetgid);
		if (NULL != pMonster)
		{
			pMonster->GetData().x = x;
			pMonster->GetData().y = y;
			pMonster->GetData().degree = degree;
		}
	}
	else if( ismonster == 3 )
	{
		targetgid = GID;
		NLogic::Monster * pMonster = pUser->GetSpace()->GetMonster(targetgid);
		if (NULL != pMonster)
		{
			pMonster->GetData().x = x;
			pMonster->GetData().y = y;
			pMonster->GetData().degree = degree;
		}
	}



	::Network::Packet * pNoti = ::Network::GETPACKETPOOL()->SEND_NEW();
	* pNoti << targetgid << x << y << degree << ismonster;
	pNoti->MakePacket(CMD_SC_STOP);

	pSpace->SendAllExceptMe(pNoti, pUser);
}

} /*NAction*/ } /*NCommand*/ } /*ProjectZ*/
